﻿
using AuthorizationServicesTest.AuthorizationServices;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AuthorizationServicesTest
{
    /// <summary>
    /// Summary description for AuthorizationServices
    /// </summary>
    [TestClass]
    public class AuthorizationServiceTest
    {
        public AuthorizationServiceTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void GetAllApplications()
        {
            var client = new AuthorizationServiceClient(Properties.Settings.Default.DefaultBinding);
            
            try
            {
                client.GetAllApplications();
                client.Close();
            }
            catch
            {
                client.Abort();
            }
            //
            // TODO: Add test logic	here
            //
        }

        [TestMethod]
        public void GetApplication()
        {
            var client = new AuthorizationServiceClient(Properties.Settings.Default.DefaultBinding);

            try
            {
                client.GetApplication("InterfaceUnica");
                client.Close();
            }
            catch
            {
                client.Abort();
            }
            //
            // TODO: Add test logic	here
            //
        }

        [TestMethod]
        public void GetAllOperations()
        {
            var client = new AuthorizationServiceClient(Properties.Settings.Default.DefaultBinding);
            
            try
            {

                client.GetAllOperations("InterfaceUnica");
            }
            catch
            {
                client.Abort();
            }
        }

        [TestMethod]
        public void GetAllOperationsFromAllApplications()
        {
             var client = new AuthorizationServiceClient(Properties.Settings.Default.DefaultBinding);

             try
             {
                 ApplicationCollection apps = client.GetAllApplications();

                 foreach (var app in apps)
                 {
                     client.GetAllOperations(app.Name);
                 }
             }
             catch
             {
                 client.Abort();
             }
        }
    }
}
